package com.example.android.helloactivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

public class SetGameActivity extends Activity{
	
	public void onCreate(Bundle savedInstanceState){
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.set_game_activity);
		
		final Intent intent=this.getIntent();
		//final Bundle bundle=intent.getExtras();
		
		final EditText black=(EditText)findViewById(R.id.edit_text_black);
		final EditText white=(EditText)findViewById(R.id.edit_text_white);
		final CheckBox check=(CheckBox)findViewById(R.id.checkbox_accept);
		Button btn_ok=(Button)findViewById(R.id.button_ok);
		
		Bundle bundle=intent.getExtras();
        
        black.setText(bundle.getString("player_black"));
        white.setText(bundle.getString("player_white"));
        
        if(1 == bundle.getInt("playWithPhone")){
        	
        	check.setChecked(true);
        }else{
        	check.setChecked(false);
        }
        
        btn_ok.setOnClickListener(new Button.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Bundle bundle=intent.getExtras();
				String player_black=black.getText().toString();
				String player_white=white.getText().toString();;
				int playWithPhone=0;
				if(check.isChecked()){
					playWithPhone=1;
				}
				
				//Log.d("Debug","222222    "+playWithPhone+"        222222222");
				bundle.putInt("playWithPhone", playWithPhone);
				bundle.putString("player_black", player_black);
				bundle.putString("player_white", player_white);
				//return the value of setting
				//the next should be called ,or cannot return the value
				intent.putExtras(bundle);
				SetGameActivity.this.setResult(RESULT_OK,intent);
				SetGameActivity.this.finish();
			}
        	
        });
        
        //
        //get the highth and width of screen
        //
        
        DisplayMetrics dm = new DisplayMetrics(); 
    	//int screenWidth=320;
    	int screenHeight=480;
        dm = this.getApplicationContext().getResources().getDisplayMetrics(); 
        //screenWidth = dm.widthPixels; 
        screenHeight = dm.heightPixels; 
        
        int upTop=screenHeight/5;
        TextView view_empty=(TextView)findViewById(R.id.set_view_empty);
        view_empty.setHeight(upTop);
        
        
	}
}